package com.bwie.parkdemo.mvvm.model;

import android.content.Context;

import com.bwie.lib_core.base.BaseEntity;
import com.bwie.lib_core.mvvm.base.BaseModel;
import com.bwie.lib_core.network.HttpRetrofitFactory;
import com.bwie.lib_core.network.HttpType;
import com.bwie.parkdemo.dao.LoginUserServe;
import com.bwie.parkdemo.mvvm.model.entity.AppointRepairEntity;
import com.bwie.parkdemo.mvvm.model.entity.LoginEntity;
import com.bwie.parkdemo.mvvm.model.entity.RepairEntity;
import com.bwie.parkdemo.mvvm.model.entity.RepairUserEntity;

import java.util.ArrayList;
import java.util.List;

import io.reactivex.Observable;
import okhttp3.RequestBody;

/**
 * 维修model
 * */
public class RepairModel extends BaseModel{

    //指定维修人请求
    @Override
    public Observable<BaseEntity> request(RequestBody... bodyes) {
        List<Observable<AppointRepairEntity>>list = new ArrayList<>();
        for (int i = 0;i < bodyes.length;i ++){
            Observable<AppointRepairEntity>appointRepair =
                    HttpRetrofitFactory.getInstance().factory(HttpType.TOKENINTERFACE)
                            .getRetrofit().create(Api.class).requestAppointRepair(bodyes[i]);
            list.add(appointRepair);
        }
        Observable<AppointRepairEntity>ob = Observable.merge(list);
        return changeOB(ob);
    }

    //维修列表获取
    public Observable<BaseEntity> requestRepair(){
        Observable<RepairEntity>source = HttpRetrofitFactory.getInstance()
                .factory(HttpType.TOKENINTERFACE)
                .getRetrofit().create(Api.class).requestRepair();
        return changeOB(source);
    }
    //获取维修人列表
    public Observable<BaseEntity> requestRepairUser(){
        Observable<RepairUserEntity>source = HttpRetrofitFactory.getInstance()
                .factory(HttpType.TOKENINTERFACE)
                .getRetrofit().create(Api.class).requestRepairUser();
        return changeOB(source);
    }
    //用户数据获取
    public LoginEntity.Values requestUser(Context ctx){
        return new LoginUserServe(ctx).selUser();
    }

    @Override
    public void cleared() {

    }
}
